// 文章详情api
import request from '@/utils/request'
// 获取文章详情
export const getArticleDetailApi = (artId) => {
  return request({
    url: `/v1_0/articles/${artId}`

  })
}
// 关注作者
export const followAuthorApi = (autId) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: autId
    }

  })
}
// 取消关注作者
export const unFollowAuthorApi = (autId) => {
  return request({
    url: `/v1_0/user/followings/${autId}`,
    method: 'DELETE'
  })
}

// 对文章点赞
export const likeArticleApi = (artId) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: artId
    }

  })
}

// 取消文章点赞
export const unLikeArticleApi = (artId) => {
  return request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE'
  })
}

// 获取文章评论
export const getCommentListApi = ({ limit = 10, offset = null, artId }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      limit: limit,
      offset: offset // 请求下一页评论的偏移量
    }
  })
}

// 对评论点赞
export const likeCommentApi = (commId) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: commId
    }

  })
}

// 对评论取消点赞
export const unLikeCommentApi = (commId) => {
  return request({
    url: `/v1_0/comment/likings/${commId}`,
    method: 'DELETE'
  })
}

// 发布评论**********
export const sendCommentApi = ({ artId = null, content, target }) => {
  const obj = {
    target: target, // 文章id或评论id
    content: content // 评论内容
  }
  // 如果对评论进行回复，则target为评论id，文章id需要重新传入参数
  if (artId !== null) {
    obj.art_id = artId
  }
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}
